#include "mutex.h"

CMutex::CMutex()
{
#ifdef WIN32
    InitializeCriticalSection(&m_cs);
#else
    pthread_mutex_init(&m_lock, NULL);
#endif
}

CMutex::~CMutex()
{
#ifdef WIN32
    DeleteCriticalSection(&m_cs);
#else
    pthread_mutex_destroy(&m_lock);
#endif
}

int CMutex::Lock()
{
    int result = 0;

#ifdef WIN32
    EnterCriticalSection(&m_cs);
#else
    result = pthread_mutex_lock(&m_lock);
#endif

    return result;
}

int CMutex::Unlock()
{
    int result = 0;

#ifdef WIN32
    LeaveCriticalSection(&m_cs);
#else
    result = pthread_mutex_unlock(&m_lock);
#endif

    return result;
}

//CSpinlock::CSpinlock()
//{
//#ifdef WIN32
//    InitializeCriticalSection(&m_cs);
//#else
//    pthread_spin_init(&m_spinlock, PTHREAD_PROCESS_PRIVATE);
//#endif
//}
//
//CSpinlock::~CSpinlock()
//{
//#ifdef WIN32
//    DeleteCriticalSection(&m_cs);
//#else
//    pthread_spin_destroy(&m_spinlock);
//#endif
//}
//
//int CSpinlock::Lock()
//{
//    int result = 0;
//
//#ifdef WIN32
//    EnterCriticalSection(&m_cs);
//#else
//    result = pthread_spin_lock(&m_spinlock);
//#endif
//
//    return result;
//}
//
//int CSpinlock::Unlock()
//{
//    int result = 0;
//
//#ifdef WIN32
//    LeaveCriticalSection(&m_cs);
//#else
//    result = pthread_spin_unlock(&m_spinlock);
//#endif
//
//    return result;
//}
